package Solutions

func minFlipsMonoIncr(s string) int {
    pre:=make([]int,len(s)+1)
    pre[0]=0
    for i :=0;i<len(s);i++{
        if s[i]!='0'{
            pre[i+1]=pre[i]+1
        }else{
            pre[i+1]=pre[i]
        }
    }
    last:=0
    ans:=1<<63-1
    for i:=len(s)-1;i>=0;i--{
        t:=pre[i]+last
        if t<ans{
            ans=t
        }
        if s[i]=='0'{
            last++
        }
    }
    return ans
}